package com.leeyu.rabbitmq.listener;

import com.leeyu.mapper.OrderManageMapper;
import com.leeyu.rabbitmq.config.RabbitMQConfig;
import com.leeyu.service.OrderManageService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class OrderManageListener {

    @Autowired
    private OrderManageService orderManageService;

    @RabbitListener(queues = RabbitMQConfig.DEAD_QUEUE)
    public void consume(String orderId, Channel channel, Message message) throws IOException {
        orderManageService.cancelOrder(orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
